home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Xconq 7.0d37 / source / kernel / side.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-30  |  16.4 KB  |  384 lines  |  [TEXT/KAHL]

  1. /* Definitions for sides in Xconq.
  2.    Copyright 1987, 1988, 1989, 1991, 1992, 1993, 1994 Stanley T. Shebs.
  3.  
  4. Xconq is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.  See the file COPYING.  */
  8.  
  9. /* A side mask is a bit vector, where the bit position corresponds to the
  10.    side number. */
  11.  
  12. #if MAXSIDES < 31
  13. typedef long SideMask;
  14. #define NOSIDES (0)
  15. #define ALLSIDES (-1)
  16. #define add_side_to_set(side,mask) ((mask) | (1 << ((side) ? (side)->id : 0)))
  17. #define side_in_set(side,mask) ((mask) & (1 << ((side) ? (side)->id : 0)))
  18. #else
  19. not implemented yet
  20. #endif /* MAXSIDES */
  21.  
  22. /* Doctrine is policy info that units use to help decide behavior. */
  23.  
  24. typedef struct a_doctrine {
  25.     int everaskside;            /* should this unit ever ask for orders? */
  26.     int wakeintransport;     /* be awake while in transport? */
  27.     int avoidbadterrain;     /* avoid dangerous/unproductive terrain? */
  28.     /* need something generic for event wakeup */
  29.     int lowsupplyreturn;     /* return to base if supplies low? */
  30.     short supplyspare;        /* how close to cut low supplies */
  31.     int repairreturn;        /* return to base for repairs if damaged? */
  32.     int lowammoretreat;      /* run away if ammo is low? */
  33.     int lowammoreturn;       /* return to base if ammo is low? */
  34.     short generosity;         /* how much supply to share with others */
  35.     int expendable;          /* OK to risk destruction in combat? */
  36.     short rearm;
  37.     short repair;
  38.     short resupply;
  39.     short ifnearbycombat;
  40.     short ifnearby[MAXUTYPES]; /* how to react to utype nearby */
  41.     short aggressiveness;     /* general aggressiveness */
  42.     short wakeupinterval;
  43.     short replaninterval;     /* how often to recompute plans */
  44.     short exploreimportance;  /* priority of exploration */
  45.     int exploreedges;        /* explore by going around edges? */
  46.     int buildalways;
  47.     short locked;
  48.     /* something for move order? */
  49.     short maxsubordinates;    /* general limit on number of subords */
  50.     short maxsubordtypes[MAXUTYPES];  /* per-type limit on subords */
  51.     struct a_doctrine *fallback;  /* what to use if this one says nothing */
  52. } Doctrine;
  53.  
  54. /* More convenient access of unit doctrine info. */
  55.  
  56. #define u_doctrine(side, u, slot)  \
  57.   ((((side)->udoctrine)[u]).slot)
  58.  
  59. #define units_doctrine(unit, slot)  \
  60.   ((((unit)->side->udoctrine)[(unit)->type]).slot)
  61.  
  62. /* Each Xconq player is a "side" - more or less one country.  A side may or
  63.    may not be played by a person, and may or may not have a display attached
  64.    to it.  Each side has a different view of the world.  */
  65.  
  66. typedef struct a_side {
  67.     char *name;               /* proper name of this side */
  68.     char *longname;           /* the long name of this side */
  69.     char *shortname;          /* the long name of this side */
  70.     char *noun;               /* the noun describing a member of this side */
  71.     char *pluralnoun;         /* the noun describing several members */
  72.     char *adjective;          /* adjective for members of this side */
  73.     char *colorscheme;        /* names of the side's characteristic colors */
  74.     char *emblemname;         /* name of the side's emblem */
  75.     char *sideclass;          /* general type or class description */
  76.     int id;                   /* a unique id */
  77.     Obj *symbol;              /* a symbol bound to side's id */
  78.     short controlledbyid;     /* id of controlling side */
  79.     struct a_side *controlledby;
  80.     short *trusts;            /* True if side trusts another side */
  81.     short *trades;
  82.     short *startwith;
  83.     short *counts;            /* array of numbers for identifying units */
  84.     short *tech;              /* tech level for each unit type */
  85.     short *inittech;          /* tech level at beginning of turn */
  86.     short selfunitid;         /* id of unit that embodies side */
  87.     struct a_unit *selfunit;  /* unit that embodies side */
  88.     short *terrview;          /* ptr to view of terrain */
  89.     short *unitview;          /* ptr to view of units */          
  90.     short *unitviewdate;      /* ptr to dates of views of units */          
  91.     short *mview;             /* ptr to view of cell materials */
  92.     short *weatherview;       /* ptr to view of weather */
  93.     short ingame;             /* true if side participating in game */
  94.     short priority;           /* overall action priority of this side */
  95.     short status;             /* -1/0/1 for lost/draw/won */
  96.     short lost;               /* true if this side was knocked out */
  97.     short *scores;            /* an array of scores managed by scorekeepers */
  98.     short turntimeused;       /* seconds used this turn */
  99.     short totaltimeused;      /* total seconds used */
  100.     short timeouts;           /* total timeouts used */
  101.     short timeoutsused;       /* total timeouts used */
  102.     short finishedturn;       /* true when side wants to go to next turn */
  103.     short designer;           /* true if side is doing scenario design */
  104.     short startx, starty;     /* approx center of side's "country" */
  105.     short nameslocked;
  106.     char **unitnamers;
  107.     Obj *featurenamers;
  108.     short advantage;          /* actual advantage */
  109.     short minadvantage;       /* max advantage requestable during init */
  110.     short maxadvantage;       /* min of same */
  111.     /* Never saved */
  112.     short busy;               /* true when side state not saveable */
  113.     short finalradius;
  114.     /* Pointers to the other major structures of a side. */
  115.     short playerid;           /* numeric id of the player */
  116.     struct a_player *player;  /* pointer to data about the player */
  117.     struct a_ui *ui;          /* pointer to all the user interface data */
  118.     struct a_ai *ai;          /* pointer to the AI making decisions. */
  119.     /* These are all caches, should be possible to recalc as needed. */
  120.     struct a_unit *unithead;  /* points to list of all units on this side */
  121.     struct a_unit *actorder;  /* points to first unit to act each turn */
  122.     short numwaiting;         /* number of units waiting to get orders */
  123.     short *coverage;          /* indicates how many looking at this cell */
  124.     short *numunits;          /* number of units the side has */
  125.     short *numlive;           /* number of live & in-play units the side has */
  126.     short numacting;          /* number of units that can do things */
  127.     short numfinished;        /* number of units that have finished acting */
  128.  
  129.     long turnstarttime;       /* real time at start of turn */
  130.     long lasttime;            /* when clock started counting down again */
  131.     long turnfinishtime;      /* real time when we've finished interacting */
  132.     long laststarttime;       /* ? */
  133.  
  134.     short itertime;           /* length of order repetition */
  135.     Doctrine *doctrine;       /* general doctrine */
  136.     Doctrine *udoctrine;      /* array of per-unit-type doctrines */
  137.     short doctrineslocked;
  138.     short tasklimit;          /* max length of task queues */
  139.     int respectneutrality;    /* attack neutrals automatically? */
  140.     int trustallies;          /* rely on allies for transport etc? */
  141.     short moverandomness;
  142.     int movestraight;         /* try to move in a straight line? */
  143.     short backtrackinglimit;  /* how far backwards to look for route */
  144.     int unitseveraskside;
  145.     int usemachinestrategy;   /* like setting humanp */
  146.     short realtimeout;        /* how long to wait before just going ahead */
  147.     int autofinish;           /* turn done when all units acted */
  148.     long startbeeptime;       /* after this time, beep to signal turn start */
  149.     int willingtosave;        /* will this side go along with saving the game? */
  150.     int willingtodraw;        /* will this side go along with quitters? */
  151.  
  152.     short *gaincounts;
  153.     short *losscounts;
  154.     long **atkstats;
  155.     long **hitstats;
  156.  
  157.     struct a_side *next;      /* pointer to next in list */
  158. } Side;
  159.  
  160. /* Some convenient macros. */
  161.  
  162. #define side_in_play(side) (side == NULL || side->ingame)
  163.  
  164. /* Iteration over all sides. */
  165.  
  166. /* The first "side" is just the independent units, don't usually look at it. */
  167.  
  168. #define for_all_sides(v) for (v = sidelist->next; v != NULL; v = v->next)
  169.  
  170. /* But sometimes we need to treat independents if they were on a side. */
  171.  
  172. #define for_all_sides_plus_indep(v)  \
  173.   for (v = sidelist; v != NULL; v = v->next)
  174.  
  175. /* Manipulation of numbers encoding a side's view data. */
  176.  
  177. #define terrain_view(s,x,y)  \
  178.  ((s)->terrview ? aref((s)->terrview, x, y) : terrain_at(x, y))
  179.  
  180. #define set_terrain_view(s,x,y,v) aset((s)->terrview, x, y, v)
  181.  
  182. #define buildtview(t) ((t) + 1)
  183.  
  184. #define vterrain(v) ((v) - 1)
  185.  
  186. #define UNSEEN (0)
  187.  
  188. #define terrain_view_date(s,x,y)  (-1)
  189.  
  190. #define set_terrain_view_date(s,x,y,v) /* aset((s)->unitviewdate, x, y, v) */
  191.  
  192. /* Basic view is encoded as hhhhhssssuuuuuuu + 1, where the u's are the unit
  193.    type, s's are the side number, and h's are hp.  0 == empty. */
  194.    
  195. #define unit_view(s,x,y)  \
  196.   ((s)->unitview ? aref((s)->unitview, x, y) : EMPTY)
  197.  
  198. #define set_unit_view(s,x,y,v) aset((s)->unitview, x, y, v)
  199.  
  200. #define builduview(s,u) ((((s) << 7) | (u)) + 1)
  201.  
  202. #define vside(v) ((((v) - 1) >> 7) & 0x0f)
  203.  
  204. #define vtype(v) (((v) - 1) & 0x7f)
  205.  
  206. #define EMPTY (0)
  207.  
  208. #define appears_empty(v) ((v) == EMPTY)
  209.  
  210. #define vside_indep(v) (vside(v) == 0)
  211.  
  212. #define unit_view_date(s,x,y)  \
  213.   ((s)->unitviewdate ?  aref((s)->unitviewdate, x, y) : (-1))
  214.  
  215. #define set_unit_view_date(s,x,y,v) aset((s)->unitviewdate, x, y, v)
  216.  
  217. /* (should add material and weather views here) */
  218.  
  219. /* Basic manipulation of vision coverage layer. */
  220.  
  221. #define cover(s,x,y) (((s)->coverage)[area.width*(y)+(x)])
  222.  
  223. #define set_cover(s,x,y,v) (((s)->coverage)[area.width*(y)+(x)] = (v))
  224.  
  225. #define add_cover(s,x,y,v) (((s)->coverage)[area.width*(y)+(x)] += (v))
  226.  
  227. /* Tests of who/what runs the side. */
  228.  
  229. #define side_wants_display(s) ((s)->player && (s)->player->displayname)
  230.  
  231. #define side_wants_ai(s) ((s)->player && (s)->player->aitypename)
  232.  
  233. #define side_has_display(s) (((s)->ui) != NULL)
  234.  
  235. #define side_has_ai(s) (((s)->ai) != NULL)
  236.  
  237. #define side_lost(s) ((s) != NULL && !(s)->ingame && (s)->status < 0)
  238.  
  239. #define side_drew(s) ((s) != NULL && !(s)->ingame && (s)->status == 0)
  240.  
  241. #define side_won(s) ((s) != NULL && !(s)->ingame && (s)->status > 1)
  242.  
  243. #define side_gain_count(s,u,r) (((s)->gaincounts)[3*(u)+(r)])
  244.  
  245. #define side_loss_count(s,u,r) (((s)->losscounts)[3*(u)+(r)])
  246.  
  247. #define side_atkstats(s,a,d) ((s)->atkstats[a] ? ((s)->atkstats[a])[d] : 0)
  248.  
  249. #define side_hitstats(s,a,d) ((s)->hitstats[a] ? ((s)->hitstats[a])[d] : 0)
  250.  
  251. /* Side-related variables. */
  252.  
  253. extern Side *sidelist;
  254. extern Side *lastside;
  255. extern Side *indepside;
  256. extern Side *curside;
  257. extern Side *tmpside;
  258.  
  259. extern int numsides;
  260. extern int numplayers;
  261. extern int numdesigners;
  262.  
  263. /* Definition of an agreement between sides. */
  264.  
  265. typedef struct a_agreement {
  266.     short id;                 /* a unique id */
  267.     char *typename;           /* a descriptive general name */
  268.     char *name;               /* the specific name of this agreement */
  269.     int state;                /* is this agreement in effect */
  270.     SideMask drafters;        /* sides drafting the agreement */
  271.     SideMask proposers;       /* sides ready to propose the draft agreement */
  272.     SideMask signers;         /* proposed list of signers */
  273.     SideMask willing;         /* sides that have indicated agreement so far */
  274.     SideMask knownto;         /* sides that are aware of the signed agreement */
  275.     struct a_obj *terms;      /* list of specific terms */
  276.     short enforcement;        /* true if program should attempt to enforce terms */
  277.     struct a_agreement *next;
  278. } Agreement;
  279.  
  280. enum {
  281.     draft,                    /* agreement is circulating among drafters */
  282.     proposed,                 /* agreement is proposed to prospective signers */
  283.     in_force,                 /* agreement is active */
  284.     moribund                  /* agreement has expired */
  285. };
  286.  
  287. /* Iteration over all agreements in the game. */
  288.  
  289. #define for_all_agreements(v) for (v = agreementlist; v != NULL; v = v->next)
  290.  
  291. #define any_agreements() (agreementlist != NULL)
  292.  
  293. #define side_signed_agreement(side,ag) ((ag)->signers[side_n(side)])
  294.  
  295. #define side_willing_agreement(side,ag) ((ag)->willing[side_n(side)])
  296.  
  297. #define side_knows_about_agreement(side,ag) ((ag)->knownto[side_n(side)])
  298.  
  299. /* Agreement-related variables. */
  300.  
  301. extern int numagreements;
  302.  
  303. extern Agreement *agreementlist;
  304. extern Agreement *lastagreement;
  305.  
  306. /* Note: Can't use the "Unit" typedef below, must use "struct a_unit". */
  307.  
  308. extern void init_sides PROTO ((void));
  309. extern Side *create_side PROTO ((void));
  310. extern void init_side_unithead PROTO ((Side *side));
  311. extern int side_has_units PROTO ((Side *side));
  312. extern void init_doctrine PROTO ((Side *side));
  313. extern int init_view PROTO ((Side *side));
  314. extern void calc_start_xy PROTO ((Side *side));
  315. extern char *side_name PROTO ((Side *side));
  316. extern char *side_adjective PROTO ((Side *side));
  317. extern int side_number PROTO ((Side *side));
  318. extern Side *side_n PROTO ((int n));
  319. extern int side_controls_side PROTO ((Side *side, Side *side2));
  320. extern int side_controls_unit PROTO ((Side *side, struct a_unit *unit));
  321. extern int side_sees_unit PROTO ((Side *side, struct a_unit *unit));
  322. extern int side_sees_image PROTO ((Side *side, struct a_unit *unit));
  323. extern int num_units_in_play PROTO ((Side *side, int u));
  324. extern int num_units_incomplete PROTO ((Side *side, int u));
  325. extern struct a_unit *find_next_unit PROTO ((Side *side, struct a_unit *prevunit));
  326. extern struct a_unit *find_prev_unit PROTO ((Side *side, struct a_unit *nextunit));
  327. extern struct a_unit *find_next_actor PROTO ((Side *side, struct a_unit *prevunit));
  328. extern struct a_unit *find_prev_actor PROTO ((Side *side, struct a_unit *nextunit));
  329. extern struct a_unit *find_next_mover PROTO ((Side *side, struct a_unit *prevunit));
  330. extern struct a_unit *find_prev_mover PROTO ((Side *side, struct a_unit *nextunit));
  331. extern struct a_unit *find_next_awake_mover PROTO ((Side *side, struct a_unit *prevunit));
  332. extern struct a_unit *find_prev_awake_mover PROTO ((Side *side, struct a_unit *nextunit));
  333. extern int side_initacp PROTO ((Side *side));
  334. extern int side_acp PROTO ((Side *side));
  335. extern int side_acp_reserved PROTO ((Side *side));
  336. extern int using_tech_levels PROTO ((void));
  337. extern void remove_side_from_game PROTO ((Side *side));
  338. extern int num_displayed_sides PROTO ((void));
  339. extern void set_side_name PROTO ((Side *side, Side *side2, char *newname));
  340. extern void become_designer PROTO ((Side *side));
  341. extern void become_nondesigner PROTO ((Side *side));
  342. extern int trusted_side PROTO ((Side *side1, Side *side2));
  343. extern void set_trust PROTO ((Side *side, Side *side2, int val));
  344. extern void set_mutual_trust PROTO ((Side *side, Side *side2, int val));
  345. extern void set_autofinish PROTO ((Side *side, int value));
  346. extern int enemy_side PROTO ((Side *s1, Side *s2));
  347. extern int allied_side PROTO ((Side *s1, Side *s2));
  348. extern int neutral_side PROTO ((Side *s1, Side *s2));
  349. extern void set_willing_to_save PROTO ((Side *side, int flag));
  350. extern void set_willing_to_draw PROTO ((Side *side, int flag));
  351. extern void reveal_side PROTO ((Side *sender, Side *recipient, int *types));
  352. extern void send_message PROTO ((Side *side, long sidemask, char *str));
  353. extern void receive_message PROTO ((Side *side, Side *sender, char *str));
  354. extern void all_see_occupy PROTO ((struct a_unit *unit, int x, int y, int inopen));
  355. extern void all_see_leave PROTO ((struct a_unit *unit, int x, int y, int inopen));
  356. extern void cover_area PROTO ((Side *side, struct a_unit *unit, int x0, int y0, int onoff));
  357. extern void reset_coverage PROTO ((void));
  358. extern void calc_coverage PROTO ((Side *side));
  359. extern void reset_all_views PROTO ((void));
  360. extern void reset_view PROTO ((Side *side));
  361. extern void react_to_seen_unit PROTO ((Side *side, struct a_unit *unit, int x, int y));
  362. extern void all_see_cell PROTO ((int x, int y));
  363. extern int see_cell PROTO ((Side *side, int x, int y));
  364. extern void see_exact PROTO ((Side *side, int x, int y));
  365. extern int seen_border PROTO ((Side *side, int x, int y, int dir));
  366. extern char *side_desig PROTO ((Side *side));
  367.  
  368. extern Player *add_player PROTO ((void));
  369. extern Player *find_player PROTO ((int n));
  370. extern void canonicalize_player PROTO ((Player *player));
  371. extern char *player_desig PROTO ((Player *player));
  372.  
  373. extern void init_agreements PROTO ((void));
  374. extern Agreement *create_agreement PROTO ((int id));
  375. extern char *agreement_desig PROTO ((Agreement *ag));
  376.  
  377. extern int load_side_config PROTO ((Side *side));
  378.  
  379. extern int set_side_selfunit PROTO ((Side *side, struct a_unit *unit));
  380.  
  381. #ifdef DESIGNERS
  382. extern void paint_view PROTO ((Side *side, int x, int y, int r, int tview, int uview));
  383. #endif /* DESIGNERS */
  384.